package com.fz.dao;

import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import com.fz.mybatis.MybaisHelp;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

/**
 * Created by webrx on 2017-08-24.
 */
public class BookDao implements BookMapper{

    private SqlSession session = new MybaisHelp().getSs();
    private BookMapper bm;

    public BookDao() {
        this.bm = session.getMapper(BookMapper.class);
    }

    public int insert(Book book) {
        int num = this.bm.insert(book);
        session.commit();
        session.close();
        return num;
    }

    public List<Book> queryall() {
        List<Book> books = this.bm.queryall();
        return books;
    }

    public int save(Map<String, Object> map) {
        int num = this.bm.save(map);
        session.commit();
        session.close();
        return num;
    }

    public int saves(String name, double price) {
        int num = this.bm.saves(name,price);
        session.commit();
        session.close();
        return num;
    }
}
